package org.array.struts.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import org.array.struts.action.ActionForm;

public class RequestUtils {

	public RequestUtils() {
		
	}
	
	public static ActionForm populate(HttpServletRequest request, String beanName) {
		ActionForm form = null;
		try {
			Class<?> clazz = Class.forName(beanName);
			form = (ActionForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				field.setAccessible(true);
				field.set(form, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
		
		return form;
	}
}
